#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node{
    ll f,time,u;
    vector<ll> p;
    bool operator<(const node& a)const{
        return time>a.time;
    }
};

struct edge{
    ll u,w;
};

void solve(){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+5);
    vector<ll> b(n+5,0);
    vector<ll> res(n+5,-1);
    priority_queue<node> pq;
    vector<edge> adj[n+5];
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]==0){
            node temp;
            temp.f=2;
            temp.time=0;
            temp.u=i;
            pq.push(temp);
        }
    }
    for(ll i=0;i<k;i++){
        node temp;
        temp.f=1;
        cin>>temp.time;
        ll t;
        cin>>t;
        while(t--){
            ll p;
            cin>>p;
            temp.p.push_back(p);
        }
        pq.push(temp);
    }
    for(ll i=0;i<m;i++){
        ll u,v,w;
        cin>>u>>v>>w;
        adj[u].push_back({v,w});
    }
    while(!pq.empty()){
        node temp=pq.top();
        pq.pop();
        if(temp.f==1){
            for(int i=0;i<temp.p.size();i++){
                if(res[temp.p[i]]==-1){
                    b[temp.p[i]]=a[temp.p[i]];
                    node tmp1;
                    tmp1.f=2;
                    tmp1.time=temp.time;
                    tmp1.u=temp.p[i];
                    pq.push(tmp1);
                }
            }
        }else{
            b[temp.u]++;
            if(b[temp.u]<a[temp.u])continue;
            if(res[temp.u]!=-1)continue;
            res[temp.u]=temp.time;
            for(int i=0;i<adj[temp.u].size();i++){
                node temp1;
                temp1.f=2;
                temp1.time=temp.time+adj[temp.u][i].w;
                temp1.u=adj[temp.u][i].u;
                pq.push(temp1);
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<res[i]<<' ';
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}